import { createSlice } from '@reduxjs/toolkit';

// 更新所有课程数据，确保 ID 和标题一致
export const initialCourses = [
  {
    id: 1,
    title: 'React 完全指南',
    description: '从零开始学习 React 开发，掌握核心概念和实战技能',
    instructor: 'John Doe',
    duration: '10小时',
    level: '初级',
    price: 199,
    coverImage: 'https://img.alicdn.com/i1/2145487409/O1CN01RkAibP24bN6EWcKj6_!!0-item_pic.jpg',
    rating: 4.5,
    enrollments: 1200,
    category: '编程开发',
    createTime: '2024-03-01',
    tags: ['前端开发', 'React', 'JavaScript'],
    chapters: [
      {
        id: '1-1',
        title: '第1章：React 基础概念',
        type: 'video',
        duration: 1800,
        description: '学习 React 的核心概念和基本用法'
      },
      {
        id: '1-2',
        title: '第2章：组件化开发',
        type: 'video',
        duration: 2400,
        description: '深入理解 React 组件开发'
      }
    ]
  },
  {
    id: 2,
    title: 'Node.js 实战课程',
    description: '使用 Node.js 构建后端服务，掌握服务端开发技能',
    instructor: 'Jane Smith',
    duration: '12小时',
    level: '中级',
    price: 299,
    coverImage: 'https://www.manongbook.com/d/file/front/773eb8c96bd1c7882581a5edadc0fcda0.jpg',
    rating: 4.7,
    enrollments: 800,
    category: '编程开发',
    createTime: '2024-03-01',
    tags: ['后端开发', 'Node.js', 'JavaScript'],
    chapters: [
      {
        id: '2-1',
        title: '第1章：Node.js 基础',
        type: 'video',
        duration: 2100,
        description: '了解 Node.js 运行时环境和基本概念'
      },
      {
        id: '2-2',
        title: '第2章：Express 框架',
        type: 'video',
        duration: 2700,
        description: '学习使用 Express 构建 Web 应用'
      }
    ]
  },
  {
    id: 3,
    title: 'Vue.js 实战教程',  // 更新课程标题
    description: '从入门到精通 Vue.js 框架开发',
    instructor: 'Mike Johnson',
    duration: '8小时',
    level: '中级',
    price: 399,
    coverImage: 'https://img.alicdn.com/i2/757240263/O1CN01JF86l11DoUrQir1cP_!!757240263.jpg',
    rating: 4.8,
    enrollments: 500,
    category: '编程开发',
    createTime: '2024-03-01',
    tags: ['前端开发', 'Vue.js', 'JavaScript'],
    chapters: [
      {
        id: '3-1',
        title: '第1章：Vue.js 基础',
        type: 'video',
        duration: 1800,
        description: '学习 Vue.js 的核心概念和基础语法'
      },
      {
        id: '3-2',
        title: '第2章：Vue 组件开发',
        type: 'video',
        duration: 2400,
        description: '深入学习 Vue 组件的开发和使用'
      }
    ]
  },
  {
    id: 4,
    title: '前端工程化实践',
    description: '现代前端开发工具链与最佳实践，掌握前端工程化能力',
    instructor: 'Mike Johnson',
    duration: '16小时',
    level: '高级',
    price: 399,
    coverImage: 'https://img.alicdn.com/i2/757240263/O1CN01JF86l11DoUrQir1cP_!!757240263.jpg',
    rating: 4.8,
    enrollments: 500,
    category: '编程开发',
    createTime: '2024-03-01',
    tags: ['前端开发', 'webpack', 'CI/CD'],
    chapters: [
      {
        id: '4-1',
        title: '第1章：前端工程化概述',
        type: 'video',
        duration: 1800,
        description: '了解前端工程化的意义和发展'
      },
      {
        id: '4-2',
        title: '第2章：构建工具使用',
        type: 'video',
        duration: 2400,
        description: '掌握常用构建工具的配置和使用'
      },
      {
        id: '4-3',
        title: '第3章：自动化测试',
        type: 'video',
        duration: 2700,
        description: '学习前端自动化测试策略和方法'
      }
    ]
  },
  {
    id: 5,
    title: '英语口语进阶',
    description: '提升英语口语表达能力和交际技巧，掌握地道表达',
    instructor: 'Sarah Wilson',
    duration: '20小时',
    level: '中级',
    price: 299,
    coverImage: 'https://img.alicdn.com/imgextra/i3/O1CN01Z5paLz1O0zuCI7iSf_!!6000000001644-2-tps-884-496.png',
    rating: 4.9,
    enrollments: 1500,
    category: '语言学习',
    createTime: '2024-02-15',
    tags: ['英语', '口语', '商务英语'],
    chapters: [
      {
        id: '5-1',
        title: '第1章：发音技巧',
        type: 'video',
        duration: 2100,
        description: '掌握英语发音规则和技巧'
      },
      {
        id: '5-2',
        title: '第2章：日常对话',
        type: 'video',
        duration: 2400,
        description: '练习常用生活场景对话'
      },
      {
        id: '5-3',
        title: '第3章：商务英语',
        type: 'video',
        duration: 2700,
        description: '学习商务场合的英语表达'
      }
    ]
  },
  {
    id: 6,
    title: '日语N2备考',
    description: 'JLPT N2考试全程备考指导，系统提升日语水平',
    instructor: 'Tanaka Yuki',
    duration: '20小时',
    level: '中级',
    price: 499,
    coverImage: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.fn9F0Aog6RbS_BdPK9EevwHaHa',
    rating: 4.9,
    enrollments: 1500,
    category: '语言学习',
    createTime: '2024-02-20',
    tags: ['日语', 'JLPT', '考试'],
    chapters: [
      {
        id: '6-1',
        title: '第1章：文字词汇',
        type: 'video',
        duration: 2400,
        description: 'N2级别词汇和汉字学习'
      },
      {
        id: '6-2',
        title: '第2章：语法精讲',
        type: 'video',
        duration: 2700,
        description: 'N2考试重点语法讲解'
      },
      {
        id: '6-3',
        title: '第3章：听力训练',
        type: 'video',
        duration: 2400,
        description: 'N2听力考试专项训练'
      }
    ]
  },
  {
    id: 7,
    title: '数字插画基础',
    description: '从零开始学习数字插画创作，掌握专业创作技巧',
    instructor: 'Lisa Chen',
    duration: '16小时',
    level: '初级',
    price: 359,
    coverImage: 'https://tse1-mm.cn.bing.net/th/id/OIP-C.iRmglLFsdkSUAfs99K7-ogHaHa',
    rating: 4.8,
    enrollments: 1200,
    category: '艺术设计',
    createTime: '2024-03-15',
    tags: ['插画', '设计', '艺术'],
    chapters: [
      {
        id: '7-1',
        title: '第1章：绘画基础',
        type: 'video',
        duration: 2100,
        description: '学习数字绘画的基本技巧'
      },
      {
        id: '7-2',
        title: '第2章：上色技法',
        type: 'video',
        duration: 2400,
        description: '掌握数字插画的上色方法'
      },
      {
        id: '7-3',
        title: '第3章：场景创作',
        type: 'video',
        duration: 2700,
        description: '学习场景插画的创作方法'
      }
    ]
  }
];

const courseSlice = createSlice({
  name: 'course',
  initialState: {
    courses: initialCourses,
    loading: false,
    error: null,
    currentCourse: null,
    filters: {
      level: 'all',
      priceRange: 'all',
      rating: 'all'
    }
  },
  reducers: {
    setCourses: (state, action) => {
      state.courses = action.payload;
    },
    setCurrentCourse: (state, action) => {
      state.currentCourse = action.payload;
    },
    setLoading: (state, action) => {
      state.loading = action.payload;
    },
    setError: (state, action) => {
      state.error = action.payload;
    },
    setFilters: (state, action) => {
      state.filters = { ...state.filters, ...action.payload };
    }
  }
});

export const {
  setCourses,
  setCurrentCourse,
  setLoading,
  setError,
  setFilters
} = courseSlice.actions;

export default courseSlice.reducer;